package com.itheima.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.domain.db.Log;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface LogMapper extends BaseMapper<Log> {


    //根据时间和类型查询数据
    @Select("SELECT COUNT(*) FROM tb_log WHERE TYPE=#{type} AND log_time=#{today}")
    Integer findNumRegistered(@Param("type") String type, @Param("today") String today);

    //查询活跃用户数
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log WHERE  log_time=#{today}")
    Integer findNumActive(String today);

    //次日留存用户数
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log WHERE log_time=#{today} AND user_id IN (\n" +
            "  SELECT user_id FROM tb_log WHERE log_time=#{yesterday} AND TYPE='0102'\n" +
            ")")
    Integer findAumRetention1d(@Param("yesterday") String yesterday, @Param("today") String today);

    /*@Select("SELECT * FROM tb_log WHERE log_time  BETWEEN #{startDate} AND #{endDate} AND user_id = #{userId} LIMIT #{pageNumber},#{pageSize}")
    List<Log> findByNickName(
            @Param("pageNumber") Integer pageNumber,
            @Param("pageSize") Integer pageSize,
            @Param("startDate") String startDate,
            @Param("endDate") String endDate,
            @Param("userId") Long userId);

    @Select("SELECT * FROM tb_log WHERE log_time  BETWEEN #{startDate} AND #{endDate} LIMIT #{pageNumber},#{pageSize}")
    List<Log> findAll(
            @Param("pageNumber") Integer pageNumber,
            @Param("pageSize") Integer pageSize,
            @Param("startDate") String startDate,
            @Param("endDate") String endDate);*/

}